package function;

import model.Author;
import model.Book;
import model.GetAuthors;

import java.util.List;
import java.util.function.Function;
import java.util.stream.Stream;

public class FlatMap {
    public static void main(String[] args) {
        List<Author> authors = GetAuthors.getAuthors();
        authors.stream()
                .flatMap(new Function<Author, Stream<Book>>() {
                    @Override
                    public Stream<Book> apply(Author author) {
                        return author.getBooks().stream();
                    }
                })
                .distinct()
                .forEach((book)-> System.out.println(book.getName()));

    }
}
